package edu.uc.labs.MobilePrinting.Daemon;

import static edu.uc.labs.MobilePrinting.Configurator.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author Matt Silbernagel
 *
 */
public class RegistryWrapper extends Thread {

	public void run(){
		String line;
		String error;
		String eValue = null, rValue = null;
		try {
			
			String command = JAVAHOME + DELIM + "bin" + DELIM + "rmiregistry";
			LOGGER.debug("The command to run for the RegistryWrapper is " + command );
			Process process = Runtime.getRuntime().exec(command);
			
			// Get the output and error streams
			BufferedReader output = new BufferedReader(new InputStreamReader(process
					.getInputStream()));
			
			BufferedReader errput = new BufferedReader(new InputStreamReader(process
					.getErrorStream()));
			
			// Read the output
			while ((line = output.readLine()) != null) {
				rValue += line;
			}
			
			// Read the errors
			while ((error = errput.readLine()) != null){
				eValue += error;
			}
			
			LOGGER.debug("rmiregistry output " + rValue);
			LOGGER.debug("rmiregisty error " + eValue);
			
			
		} catch (IOException e) {
			LOGGER.error("IOException: failed trying to start the rmiregistry - " + e.toString());
			return;
		}
		
	}
	
	public void halt(){
		if( this.isAlive() ){
			return;
		}
	}
	
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
